package com.xiaoqi.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xiaoqi.dao.MemberDao;
import com.xiaoqi.dao.OrderDao;
import com.xiaoqi.service.ReportService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author PC
 * creationTime: 2022/11/29 15:04
 */
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private MemberDao memberDao;

    /**
     * 运营数据的查询包括会员，预约与套餐
     * @return
     */
    @Override
    public Map<String, Object> getBusinessReportData() {
        //格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //准备数据
        //当前日期
        String DateStr = sdf.format(new Date());
        //获取当天会新增数量
        Integer todayNewMember = memberDao.findMemberCountByDate(DateStr);
        //总会员数
        Integer totalMember = memberDao.findMemberTotalCount();
        //当周新增的会员数
        Integer thisWeekNewMember = memberDao.findMemberByWeekCount(DateStr);
        //当月新增的会员数
        Integer thisMonthNewMember = memberDao.findMemberByMonthCount(DateStr);
        //今日预约数量
        Integer todayOrderNumber = orderDao.findOrderCountByDate(DateStr);
        //今日到诊数量
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(DateStr);
        //当周的预约数量
        Integer thisWeekOrderNumber = orderDao.findOrderCountByWeek(DateStr);
        //当周的预约到诊数量
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountByWeek(DateStr);
        //当月的预约数量
        Integer thisMonthOrderNumber = orderDao.findOrderCountByMonth(DateStr);
        //当月的预约到诊数量
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountByMonth(DateStr);
        //热门套餐
        List<Map> hotSetmeal = orderDao.findHotSetmeal();
        //返回给前端的数据，多条数据用map来装
        Map<String, Object> map = new HashMap<>();
        //将数据加入map
        map.put("reportDate",DateStr);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);
        return map;
    }
}
